/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: type_defs.h
 *
 * Purpose: base type define
 *
 * Developer:
 *   wen.gu , 2021-05-10
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __TYPE_DEFS_H__
#define __TYPE_DEFS_H__

#include <stdint.h>
#include <vector>
#include <memory>
/******************************************************************************
 **    MACROS
 ******************************************************************************/

#define MAKE_EVENT_ID(group_id, event_id) (((((MessageId)(group_id)) << 24) & 0xFF000000) | (event_id))
#define MAKE_FIELD_ID(field_id)  (((MessageId)(0x10000)) | (0xffff & (field_id))
#define MAKE_METHOD_ID(method_id) (((MessageId)(0x20000)) | (0xffff & (field_id)) 

#define GET_GROUP_ID(msg_id)    (((msg_id) >> 24) & 0xff)
#define GET_EVNET_ID(msg_id)    ((msg_id) & 0xffff)
#define GET_FIELD_ID(msg_id)    ((msg_id) & 0xffff)
#define GET_METHOD_ID(msg_id)   ((msg_id) & 0xffff)

#define MSG_IS_EVENT(msg_id)   ((((msg_id) >> 16) & 0xff) == 0x00)
#define MSG_IS_FIELD(msg_id)   ((((msg_id) >> 16) & 0xff) == 0x01)
#define MSG_IS_METHOD(msg_id)  ((((msg_id) >> 16) & 0xff) == 0x02) 

/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/

using ClientId = uint32_t;
using SessionId = uint32_t;
using MessageId = uint32_t;

using EventId = uint16_t;
using GroupId = uint8_t;
using FieldId = uint16_t;
using MethodId = uint16_t;

/**
 *  Event id -> message Id:  |group id(1 byte)| 00 (1byte)|event id(2 byte)|
 *  Field id -> message Id:  |0001(2byte)|field id(2 byte)|
 *  Method id -> message Id: |0002(2byte)|method id(2 byte)| 
 */


enum class ErrorCode: uint8_t
{
    OK = 0,
    Fail = 1,
    BadParameter = 2,
    NoInit = 3,
    Eof = 4,
    NotImplemented = 5,
    NotFound = 6,
    Undefined = 7,
    InvaildName = 8,
    InsufficientResources = 9,
    InvalidStatus = 10,
    OutOfRange = 11,
    UnsupportedType = 12,
    Timeout = 13,
    BadAddress = 14,
    ConnectionAborted = 15, /**< connection aborted(ECONNABORTED) */
    ConnectionAlreadyInProgress = 16, /**< connection already in progress(EALREADY) */
    ConnectionRefused = 17, /**< connection refused(ECONNREFUSED) */
    ConnectionReset = 18, /**< connection reset(ECONNRESET) */
    BadMessage = 19, 
    OperationCanceled = 20, /**< operation canceled(ECANCELED) */
    OperationInProgress = 21, /**< operation in progress(EINPROGRESS) */
    OperationNotPermitted = 22, /**< operation not permitted(EPERM) */
    OperationNotSupported = 23, /**< operation not supported(EOPNOTSUPP) */
    OperationWouldBlock = 24, /**< operation would block(EWOULDBLOCK) */
    OutOfMemory = 25,  
    AlreadyExisted = 26, /**< target already existed */
    ResourceIsBusy = 27, /**< target is busing, */
    Mismatch = 28,       /**< the condition mismatch */   
    SeriablizeFailed = 29, /**< serialize data failed */ 
    DeserializeFailed = 30, /**< Deserialize data failed */
    InvokeFailed = 31,  /**< do invoke failed at proxy side */
};

enum class ComProtocolType: uint8_t
{
    kUnknown = 0,
    kFDBus,
};

/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/



#endif /** !__TYPE_DEFS_H__ */

